package leetcode.剑指offer.前40;

import leetcode.剑指offer.pojo.ListNode;
import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/28 11:36
 * @description :https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/
 */
public class 剑指_22_链表中倒数第k个节点 {
    @Test
    public void test() {
        Solution solution = new Solution();

    }


    class Solution {
        public ListNode getKthFromEnd(ListNode head, int k) {
            ListNode tmpA = head;
            while (k > 0 && tmpA != null) {
                tmpA = tmpA.next;
                k--;
            }
            ListNode tmpB = tmpA;
            tmpA = head;
            while (tmpB != null) {
                tmpA = tmpA.next;
                tmpB = tmpB.next;
            }
            return tmpA;
        }
    }


}
